import { Navigate } from "react-router-dom";
import { lazy } from "react";
import { ProtectedRoute } from "./protectedRoute";

// 懒加载组件
const Home = lazy(() => import("@/pages/Dashboard/Home"));
const Forget = lazy(() => import("@/pages/Forget"));
const Register = lazy(() => import("@/pages/Register"));
const Login = lazy(() => import("@/pages/Login"));
const NotFound = lazy(() => import("@/pages/NotFound"));
const Dashboard = lazy(() => import("@/pages/Dashboard"));
const Message = lazy(() => import("@/pages/Dashboard/Message"));
const Member = lazy(() => import("@/pages/Dashboard/Member"));
export const routes = [
  {
    path: "/",
    element: <Navigate to="/dashboard" replace />,
    meta: { title: "首页" },
  },
  {
    path: "/dashboard",
    element: (
      <ProtectedRoute>
        <Dashboard />
      </ProtectedRoute>
    ),
    meta: { title: "控制台" },
    children: [
      {
        path: "",
        element: <Navigate to="/dashboard/home" replace />,
      },
      {
        path: "home",
        element: <Home />,
        meta: {
          title: "首页",
        },
      },
      {
        path: "message",
        element: <Message />,
        meta: {
          title: "消息中心",
        },
      },
      {
        path: "member",
        element: <Member />,
        meta: {
          title: "个人中心",
        },
      },
    ],
  },
  {
    path: "/login",
    element: <Login />,
    meta: { title: "登录" },
  },
  {
    path: "/forget",
    element: <Forget />,
    meta: { title: "忘记密码" },
  },
  {
    path: "/register",
    element: <Register />,
    meta: { title: "注册" },
  },
  {
    path: "/404",
    element: <NotFound />,
    meta: { title: "Not Found" },
  },
  {
    path: "*",
    element: <Navigate to="/404" replace />,
  },
];
